﻿/* 
 * File:   dict.h
 * Author: aple
 */

#ifndef __DICT__H_H_
#define	__DICT__H_H_

#include "stdint.h"

#ifdef	__cplusplus
extern "C" {
#endif

#define DICT_LEN(x) (sizeof(x)/sizeof(x[0]))

typedef struct
{
	uint8_t src;
	uint8_t des;
} dict_u8_type;

// 返回结果索引，-1代表未搜索到，字典SRC为顺序列表, des保存结果，无需保存时设为0
int16_t dict_u8_get(const dict_u8_type *dict, int16_t Len, uint8_t src, uint8_t *des);
// 无序列表，功能同上，遍历法，速度较慢
int16_t dict_disorder_u8_get(const dict_u8_type *dict, int16_t Len, uint8_t src, uint8_t *des);

typedef struct
{
	int8_t src;
	int8_t des;
} dict_i8_type;

// 返回结果索引，-1代表未搜索到，字典SRC为顺序列表, des保存结果，无需保存时设为0
int16_t dict_i8_get(const dict_i8_type *dict, int16_t Len, int8_t src, int8_t *des);
// 无序列表，功能同上，遍历法，速度较慢
int16_t dict_disorder_i8_get(const dict_i8_type *dict, int16_t Len, int8_t src, int8_t *des);

typedef struct
{
	uint16_t src;
	uint16_t des;
} dict_u16_type;

// 返回结果索引，-1代表未搜索到，字典SRC为顺序列表, des保存结果，无需保存时设为0
int16_t dict_u16_get(const dict_u16_type *dict, int16_t Len, uint16_t src, uint16_t *des);
// 无序列表，功能同上，遍历法，速度较慢
int16_t dict_disorder_u16_get(const dict_u16_type *dict, int16_t Len, uint16_t src, uint16_t *des);

typedef struct
{
	int16_t src;
	int16_t des;
} dict_i16_type;

// 返回结果索引，-1代表未搜索到，字典SRC为顺序列表, des保存结果，无需保存时设为0
int16_t dict_i16_get(const dict_i16_type *dict, int16_t Len, int16_t src, int16_t *des);
// 无序列表，功能同上，遍历法，速度较慢
int16_t dict_disorder_i16_get(const dict_i16_type *dict, int16_t Len, int16_t src, int16_t *des);

typedef struct
{
	char * src;
	char * des;
} dict_str_type;
// 无序列表，遍历法
int16_t dict_str_get(const dict_str_type *dict, char * src, char * * des);



#ifdef	__cplusplus
}
#endif

#endif	/* __DICT__H_H_ */

